﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using ScFramework.Core;
using System;

public class EditManager : LogicModuleBase<EntityResource,UserManager>
{
    GameObject map;
    //   List<string> editingObjs;
    List<EntityData> objList;
    public override void OnInit(object args = null)
    {
        base.OnInit(args);

        map = GameObject.Find("Map");
        var tp = map.GetChildren();
        tp.RemoveAll(s => s.activeSelf == false);

        objList = new List<EntityData>();
        //editingObjs =tp.ConvertAll(s => s.name.Split(' ')[0]);
        if (SysModule1.IsHost == false)
        {
            return;
        }
        foreach(var x in tp)
        {
            Dispatch(EntityDataEvent.Create,new DataCreateArgs { ID= EntityUtilities.GetIdByName(x.name.Split(' ')[0]) 
                ,actions=(EntityData e) =>
                {
                    new STransformVEx(e.GetComponentData<STransform>()).LocalPosition = x.transform.localPosition;
                    objList.Add(e);
                }
            
            
            },false);
        }
    //    Dispatch(ObjectPresentPosEvent.ToWorld, new ObjectPresentPosChangeArgs { Entities=objList,LastPresentPos=ObjectPresentPos.Bench},false);
        foreach(var x in map.GetChildren())
        {
            GameObject.Destroy(x);
        }
    }
    public override void FixedUpdate()
    {
        base.FixedUpdate();
    }
}